//////////////////////////////////////////////////////////////////////
//
//	Crytek CryENGINE Source code
//
//	File:FileReadSequencer.h
//  Description: 
//    During level or menu loading - preload all file data ahead.
//    Allows to completely eliminate DVD seek/load time
//    Usually all CVars has to be set into release state for proper work of file sequencer
//
//	History:
//	  -May 24,2010: Created by Vladimir Kajalin
//
//////////////////////////////////////////////////////////////////////

#ifndef __FILEREADSEQUENCER_H__
#define __FILEREADSEQUENCER_H__

#pragma once


class CFileReadSequencer : public IFileReadSequencer
{
  struct SFileAccessStats
  {
    SFileAccessStats()
    {
      Reset();
    }

    void Reset()
    {
      ZeroStruct(ok);
      ZeroStruct(oth);
      ZeroStruct(off);
      ZeroStruct(skip);
    }

    struct SStats
    {
      SStats() { ZeroStruct(*this); }
      float fTime;
      int nBytes;
      int nReads;
    };

    string sName;
    SStats ok;
    SStats oth;
    SStats off;
    SStats skip;
  };

public:

  virtual void Init();
  virtual void StartSection(const char * pSectionName);
  virtual void UpdateCurrentThread( bool bUpdateFromNextFileRead );
  virtual void EndSection();

  static int Fread(void *pData, size_t nSize, size_t nCount, FILE * hFile);  
  static void OnFopen(FILE * hFile, const char * file, const char * mode);
  static bool IsProfiling();
  static IFileReadSequencer * GetFileReadSequencer();
  static const char * GetFileName(FILE * hFile);
  static SFileAccessStats * GetFileInfo(FILE * hFile);
  static float GetSectionTime();

  static void CloseSeqFile();
  static void LogStatus(const char * pSectionName, FILE * hFile);
  static void Log(const char * szFormat, ...);

  static SFileAccessStats m_seqStats;
  static int m_nMessageOrder;
  static int m_nSequencerMode;
  static int m_nSequencerProfile;
  static string m_sSectionName;
  static DWORD m_dwTargetThread;
  static FILE * m_hWriteFile;
  static int m_nCurPageStartOffset;
  static int m_nCurPageBytes;
  static class CReadSequencerThread * m_pReadThread;
  static std::map<FILE*,SFileAccessStats> m_mapOpenFiles;
  static CryCriticalSection m_csFread;
  static CryCriticalSection m_csMapOpenFiles;
  static CTimeValue m_sectionStartTime;
  static PodArray<struct SDeferredBlock*> m_arrDeferredBlocks;
	
private:
	CFileReadSequencer();
};

#endif
